home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / highlight / highlight-W32GUI-2.2-10b-Setup.exe / {app} / src / ASStreamiterator.cpp < prev    next >
C/C++ Source or Header  |  2004-01-31  |  1KB  |  83 lines

  1. #include "compiler_defines.h"
  2. #include "ASStreamIterator.h"
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string>
  7.  
  8. using namespace astyle;
  9.  
  10. ASStreamIterator::ASStreamIterator(istream *in)
  11. {
  12.   inStream = in;
  13. }
  14.  
  15. ASStreamIterator::~ASStreamIterator()
  16. {
  17.   delete inStream;
  18. }
  19.  
  20.  
  21. bool ASStreamIterator::hasMoreLines() const
  22.   {
  23.     if (*inStream)
  24.       return true;
  25.     else
  26.       return false;
  27.   }
  28.  
  29. /*
  30. string ASStreamIterator::nextLine()
  31. {
  32.    char theInChar;
  33.    char peekedChar;
  34.    int  theBufferPosn = 0;
  35.  
  36.    //
  37.    // treat '\n', '\r', '\n\r' and '\r\n' as an endline.
  38.    //
  39.    while (theBufferPosn < 2047 && inStream->get(theInChar))
  40.    // while not eof
  41.    {
  42.       if (theInChar != '\n' && theInChar != '\r')
  43.       {
  44.      buffer[theBufferPosn] = theInChar;
  45.          theBufferPosn++;
  46.       }
  47.       else
  48.       {
  49.     peekedChar = inStream->peek();
  50.     if (peekedChar != theInChar && (peekedChar == '\r' || peekedChar == '\n') )
  51.          {
  52.             inStream->get(theInChar);
  53.          }
  54.          break;
  55.       }
  56.    }
  57.    buffer[theBufferPosn] = '\0';
  58.  
  59.    return string(buffer);
  60. }
  61. */
  62.  
  63.  
  64. string ASStreamIterator::nextLine()
  65. {
  66.   char *srcPtr;
  67.   char *filterPtr;
  68.  
  69.   inStream->getline(buffer, 2047);
  70.   srcPtr = filterPtr = buffer;
  71.  
  72.   while (*srcPtr != 0)
  73.     {
  74.       if (*srcPtr != '\r')
  75.         *filterPtr++ = *srcPtr;
  76.       srcPtr++;
  77.     }
  78.   *filterPtr = 0;
  79.  
  80.   return string(buffer);
  81. }
  82.  
  83.